#pragma once

#include "../VulkanRHI.h"
#include <unordered_map>


class RHIShader;

class ShaderMap
{

public:

	ShaderMap();

	~ShaderMap();

	RHIShader* GetShader(const std::string name) const;

	template<typename ShaderType>
	ShaderType* GetShader() const;

	template<typename ShaderType>
	void RegisterShader(ShaderType* shader);

	void CompileShader();

private:

	std::unordered_map<std::string, RHIShader*> mOwnMap;

	std::unordered_map<std::string, RHIShader*> mDelayMap;
};


template<typename ShaderType>
ShaderType* ShaderMap::GetShader() const
{
	if (mOwnMap.find(ShaderType::GetType()) != mOwnMap.end())
	{
		return (ShaderType*)mOwnMap.find(ShaderType::GetType())->second;
	}
	assert(0);
	return nullptr;
}

template<typename ShaderType>
void ShaderMap::RegisterShader(ShaderType* shader)
{
	if (shader == nullptr)
	{
		return;
	}
	if (mDelayMap.find(ShaderType::GetType()) != mDelayMap.end())
	{
		assert(false);
		return;
	}
	mDelayMap.insert({ ShaderType::GetType(), shader });
}

